package com.leetcode.problems_11;

/**
 * 0037：搜索插入位置
 *
 * @Author: WuPeng
 * @Date: 2021/5/19 7:58 下午
 */
public class SearchSiteForInsert {

    /**
     * 二分法查找
     */
    public int solution(int[] arr, int target){
        int left=0, right=arr.length-1;
        while (left <= right){
            int mid = (left + right) / 2;
            if (arr[mid] == target){
                return mid;
            } else if (arr[mid] < target){
                left = mid + 1;
            } else if (arr[mid] > target){
                right = mid -1;
            }
        }
        return right+1;
    }

    /**
     * 暴力查找
     */
    public static int solution2(int[] arr, int target){
        int len = arr.length;
        for(int i=0; i<len; i++){
            if(arr[i] >= target){
                return i;
            }
        }
        return len;
    }

    public static void main(String[] args) {
        int[] arr = {1};
        System.out.println(solution2(arr, 0));
    }

}
